<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
    <script src="/resources/js/function/Local.js"></script>
    <script src="/resources/js/function/Session.js"></script>
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
    <script src="/resources/layui/layui.js"></script>
    <script src="/resources/js/json2.js"></script>
    <script src="/resources/js/jquery.min.js"></script>
</head>
<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-sm6 layui-col-sm-offset3">
            <header class="layui-elip"><h2>登录</h2></header>
            <hr>
            <form class="layui-form" id="form" lay-filter="login">
                <div class="layui-form-item">
                    <label class="layui-form-label">员工账号</label>
                    <div class="layui-input-block">
                        <input autofocus type="text" name="user" required  lay-verify="required" placeholder="请输入员工账号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" required lay-verify="required" placeholder="请输入员工密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button lay-submit lay-filter="login" class="layui-btn" style="margin-left: 110px;">立即登录</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
<script>
    layui.use(['form','layer','jquery'], function () {
        // 操作对象
        var form = layui.form;
        var $ = layui.jquery;
        form.on('submit(login)',function (data) {
            console.log(data);
            $.ajax({
                url:new Local().base_url + '/staff/login',
                data:data.field,
                dataType:'json',
                type:'post',
                success:function (d) {
                    if (d.code == 0){
                        //放入本地存储
                        sessionStorage.setItem(new Session().staff_login,JSON.stringify(d.data.staff_login));
                        sessionStorage.setItem(new Session().staff_roles,JSON.stringify(d.data.staff_roles));
                        sessionStorage.setItem(new Session().staff_perm,JSON.stringify(d.data.staff_perm));
                        layer.msg('登录成功！', {
                            icon: 1,
                            time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            location.href = "/html/staff/index.html";
                        });

                    }else{
                        document.getElementById("form").reset();
                        layui.form.render();
                        layer.msg(d.msg);
                    }
                }
            });
            return false;
        })
    });
</script>